﻿using SqlSugar;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;

namespace OPCTreeMonitor.SQLdb.dbModel
{

    [Table("OPCMonitorNode")]
    public class OPCMonitorNode : INotifyPropertyChanged
    {
        /// <summary>
        /// 序号
        /// </summary>
        [SugarColumn(IsPrimaryKey = true)]
        public int Index { get; set; }
        /// <summary>
        /// 组别名字
        /// </summary>
        public string FileName { get; set; }
        /// <summary>
        /// 组别名字
        /// </summary>
        public string GroupName { get; set; }
        /// <summary>
        /// 节点名字
        /// </summary>
        public string NodeName { get; set; }

        private string _nodePreSetValue;
        /// <summary>
        /// 设定值
        /// </summary>
        public string NodePreSetValue
        {
            get => _nodePreSetValue;
            set
            {
                _nodePreSetValue = value;
                OnPropertyChanged(nameof(NodePreSetValue));  // 补充通知
            }
        }

        private string _type;
        /// <summary>
        /// 数据类型
        /// </summary>
        public string Type
        {
            get => _type;
            set
            {
                _type = value;
                OnPropertyChanged(nameof(Type));
            }
        }
        /// <summary>
        /// 描述文本
        /// </summary>
        public string NodeDescription { get; set; }
        /// <summary>
        /// 写地址
        /// </summary>
        public string NodeWrite { get; set; }
        /// <summary>
        /// 读地址
        /// </summary>
        public string NodeRead { get; set; }

        /// <summary>
        /// 实时读取的值
        /// </summary>
        private string _actualRead;

        [NotMapped]
        public string ActualRead
        {
            get => _actualRead;
            set
            {
                _actualRead = value;
                OnPropertyChanged(nameof(ActualRead));
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
